package com.hz.mapper;

import com.hz.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Insert("INSERT into category (category_name, category_alias, create_user, create_time, update_time) VALUES " +
            "(#{categoryName},#{categoryAlias},#{createUser},#{createTime},#{updateTime})")
    int insert(Category category);

    @Select("select * from category where category_name=#{categoryName}")
    Category selectByName(String categoryName);

    @Select("select id,category.category_name,category.category_alias,create_time,update_time from category" +
            " where create_user = #{id}")
    List<Category> selectByUserId(Integer create_user);

    @Select("select * from category where id = #{id}")
    Category selectById(Integer id);

    @Update("update category set category_name=#{categoryName},category_alias=#{categoryAlias},update_time=now() where id = #{id}")
    int updateCategory(Integer id, String categoryName, String categoryAlias);

    @Delete("delete from category where id=#{id}")
    int deleteById(Integer id);
}
